home *** CD-ROM | disk | FTP | other *** search
/ Web Page Construction Kit 3.0 / Web Page Construction Kit 3.0.iso / pc / source / 3rdparty / java / jamba / dev / jambaobj.awx / TEMPLATE / TRWIDOBJ.JAVA < prev    next >
Encoding:
Text File  |  1996-07-15  |  6.7 KB  |  323 lines

  1. $$IF(JAMBA_EXPLCOMMENTS)
  2. /**
  3. * Jamba code template for $$JAMBA_CLASSNAME$$Obj
  4. * trwidobj.java
  5. */
  6. $$ENDIF
  7.  
  8. // All Jamba objects are located in the objects package
  9. package Aimtech.objects;
  10.  
  11. // Standard Jamba imports
  12. import java.lang.*;
  13. import java.awt.*;
  14. import java.util.*;
  15. import Aimtech.utils.*;
  16. import Aimtech.effects.*;
  17. import Aimtech.smartpage.*;
  18.  
  19. $$IF(JAMBA_EXPLCOMMENTS)
  20. /**
  21. * Implementation of Jamba $$JAMBA_CLASSNAME$$Obj object
  22. */
  23. $$ENDIF
  24.  
  25. public class $$JAMBA_CLASSNAME$$Obj extends WidgetObj implements Runnable
  26. {
  27.     // Used in objStart to check if previously stopped
  28.     private boolean bStopped = false;
  29.  
  30.     // This object's thread
  31.     Thread thread = null;
  32.  
  33. $$IF(JAMBA_EXPLCOMMENTS)
  34.     /**
  35.     * Called once, and only once, when object is first loaded. Use
  36.     * to perform one time object initialization
  37.     */
  38. $$ENDIF
  39.     public void objLoad ()
  40.     {
  41. $$IF(JAMBA_TODOCOMMENTS)
  42.         //# TODO - Insert custom code here
  43. $$ENDIF
  44.         super.objLoad();
  45.     }
  46.  
  47. $$IF(JAMBA_EXPLCOMMENTS)
  48.     /**
  49.     * Called each time the Jamba page containing the object is displayed. Use
  50.     * to allocate object resources. These resources should be freed in
  51.     * objFlush
  52.     */
  53. $$ENDIF
  54.  
  55.     public final void objPrepare()
  56.     {
  57. $$IF(JAMBA_TODOCOMMENTS)
  58.         //# TODO - Insert custom code here
  59. $$ENDIF
  60.         // Create the component for the object.
  61.         if (theComponent == null)
  62.         {
  63.             theComponent = (Component)new TemplateWidgetImp(this);
  64.         }
  65.  
  66.         super.objPrepare();
  67.     }
  68.  
  69. $$IF(JAMBA_EXPLCOMMENTS)
  70.     /**
  71.     * Called each time the Jamba page containing the object is removed from
  72.     * the list of recently accessed Jamba pages. Use to free resources
  73.     * allocated by object.
  74.     */
  75. $$ENDIF
  76.  
  77.     public void objFlush()
  78.     {
  79. $$IF(JAMBA_TODOCOMMENTS)
  80.         //# TODO - Insert custom code here
  81. $$ENDIF
  82.         super.objFlush();
  83.     }
  84.  
  85. $$IF(JAMBA_EXPLCOMMENTS)
  86.     /**
  87.     * Called in response to several events including the object being made
  88.     * visible and the HTML page containing the object being redisplayed.
  89.     */
  90. $$ENDIF
  91.     public void objStart()
  92.     {
  93.         // If object stopped by objStop(), restart it here
  94.         if (bStopped)
  95.         {
  96. $$IF(JAMBA_TODOCOMMENTS)
  97.             //# TODO - Insert custom code here
  98. $$ENDIF
  99.             start();
  100.             bStopped = false;
  101.         }
  102.  
  103.         super.objStart();
  104.     }
  105.  
  106. $$IF(JAMBA_EXPLCOMMENTS)
  107.     /**
  108.     * Called in response to several events including the object being made
  109.     * not visible and the HTML page containing the object being changed
  110.     * within a web browser such that another HTML page can be displayed.
  111.     * Use to cease any ongoing object activity.
  112.     */
  113. $$ENDIF
  114.     public void objStop()
  115.     {
  116.         if (!bStopped)
  117.         {
  118. $$IF(JAMBA_TODOCOMMENTS)
  119.         //# TODO - Insert custom code here
  120. $$ENDIF
  121.             stop();
  122.               bStopped = true;
  123.         }
  124.  
  125.         super.objStop();
  126.     }
  127.  
  128. $$IF(JAMBA_EXPLCOMMENTS)
  129.     /**
  130.      * Called when object properties are set or changed
  131.      */
  132. $$ENDIF
  133.     public synchronized void objSetProp(String name, String value)
  134.     {
  135.         if (name.equals("property1"))
  136.         {
  137. $$IF(JAMBA_TODOCOMMENTS)
  138.             //# TODO - Insert custom code here
  139. $$ENDIF
  140.         }
  141.  
  142.         else if (name.equals("property2"))
  143.         {
  144. $$IF(JAMBA_TODOCOMMENTS)
  145.             //# TODO - Insert custom code here
  146. $$ENDIF
  147.         }
  148.  
  149.         // Default property handling
  150.         else super.objSetProp(name, value);
  151.     }
  152.  
  153. $$IF(JAMBA_EXPLCOMMENTS)
  154.     /**
  155.     * Called to retrieve the current value of an object property.
  156.     */
  157. $$ENDIF
  158.     public synchronized String objGetProp(String name)
  159.     {
  160.         // If object does not track a property value in member variables or
  161.         // does not modify properties without updating the object's property
  162.         // list, it can simply allow the default property handling to occur
  163.         // and not have a case for it in the following code
  164.         if (name.equals("property1"))
  165.         {
  166. $$IF(JAMBA_TODOCOMMENTS)
  167.             //# TODO - Insert custom code here
  168. $$ENDIF
  169.         }
  170.  
  171.         else if (name.equals("property2"))
  172.         {
  173. $$IF(JAMBA_TODOCOMMENTS)
  174.             //# TODO - Insert custom code here
  175. $$ENDIF
  176.         }
  177.  
  178.         return (super.objGetProp(name));
  179.     }
  180.  
  181. $$IF(JAMBA_EXPLCOMMENTS)
  182.     /**
  183.     * Called when an object methods has been called within a ToDo list.
  184.     */
  185. $$ENDIF
  186.     public synchronized boolean objDoMethod(String method, Vector args)
  187.     {
  188.         if (method.equals ("method1"))
  189.         {
  190. $$IF(JAMBA_TODOCOMMENTS)
  191.             //# TODO - Insert custom code here
  192. $$ENDIF
  193.         }
  194.         else if (method.equals ("method2"))
  195.         {
  196. $$IF(JAMBA_TODOCOMMENTS)
  197.             //# TODO - Insert custom code here
  198. $$ENDIF
  199.         }
  200.         else
  201.         {
  202.             return (super.objDoMethod(method, args));
  203.         }
  204.  
  205.         // The method was handled
  206.         return (true);
  207.     }
  208.  
  209. $$IF(JAMBA_EXPLCOMMENTS)
  210.     /**
  211.     * Standard start method used by Jamba objects
  212.     */
  213. $$ENDIF
  214.     public void start ()
  215.     {
  216.         if (thread == null)
  217.         {
  218.             thread = new Thread (this);
  219.         }
  220.  
  221.         if (!thread.isAlive())
  222.         {
  223.             thread.start();
  224.         }
  225.     }
  226.  
  227. $$IF(JAMBA_EXPLCOMMENTS)
  228.     /**
  229.     * Standard stop method used by Jamba objects
  230.     */
  231. $$ENDIF
  232.     public void stop ()
  233.     {
  234.         if (thread != null)
  235.         {
  236.             Thread tmp = thread;
  237.             thread = null;
  238.             tmp.stop();
  239.         }
  240.     }
  241.  
  242. $$IF(JAMBA_EXPLCOMMENTS)
  243.     /**
  244.     * Object's run method for it's thread
  245.     */
  246. $$ENDIF
  247.     public void run ()
  248.     {
  249. $$IF(JAMBA_TODOCOMMENTS)
  250.         //# TODO - Insert custom code here
  251. $$ENDIF
  252.         // Must be last line in method
  253.         stop();
  254.     }
  255.  
  256. }
  257.  
  258. $$IF(JAMBA_EXPLCOMMENTS)
  259. /**
  260. * Jamba code for TemplateWidgetImp. This is the actual Java componet
  261. * created for the object. You need to supply all painting and event
  262. * handling.
  263. *
  264. * This class can be modified to extend other Java components besides
  265. * $$JAMBA_CLASSEXTEND$$.
  266. */
  267. $$ENDIF
  268. class TemplateWidgetImp extends $$JAMBA_CLASSEXTEND$$
  269. {
  270.     // Handle to the Jamba object
  271.     private BaseObj obj;
  272.  
  273. $$IF(JAMBA_EXPLCOMMENTS)
  274.     /**
  275.     * Constructor to create component
  276.     */
  277. $$ENDIF
  278.     public TemplateWidgetImp (BaseObj obj)
  279.     {
  280.         // Create the component
  281.         super();
  282.  
  283.         // Save a handle to the Jamba object
  284.         this.obj = obj;
  285.  
  286. $$IF(JAMBA_TODOCOMMENTS)
  287.         //# TODO - Insert custom code here
  288. $$ENDIF
  289.     }
  290.  
  291. $$IF(JAMBA_EXPLCOMMENTS)
  292.     /**
  293.     * Sample paint method used to validate object creation
  294.     * For a canvas class you can override the paint member like this
  295.     * public void paint (Graphics g)
  296.     * {
  297.     *     g.drawString ("Object Is Alive", 10, 20);
  298.     * }
  299.     */
  300. $$ENDIF
  301.  
  302. $$IF(JAMBA_EXPLCOMMENTS)
  303.     /**
  304.     * Handle input events and generate corresponding Jamba events
  305.     */
  306. $$ENDIF
  307.     public boolean handleEvent(Event event)
  308.     {
  309.         switch (event.id)
  310.         {
  311.             //# Sample event handling
  312.             case Event.MOUSE_UP:
  313.                 obj.processAction ("click");
  314.                 break;
  315.  
  316.             default:
  317.                 return (false);
  318.         }
  319.  
  320.         return (true);
  321.     }
  322. }
  323.